#include "ContraStateLandWater.h"




void ContraStateLandWater::setDirection(int direction, int state)
{
	if (this->preState != state) {
		this->preState = state;
		this->direction = direction;
		this->delayOnChange = 20;
		_data->notMove = true;
		if (state == _DATA_CONTRA_STATE_IN_WATER) {
			nextState = _DATA_CONTRA_STATE_ON_LAND;
			_data->state = _DATA_CONTRA_STATE_WATER_LAND;
			if (direction == 1) {
				_data->sprites->setState(_STATE_CONTRA_MOVE_RIGHT);
				_data->bodySprites->setState(_STATE_CONTRA_MOVE_RIGHT);
			} else {
				_data->sprites->setState(_STATE_CONTRA_MOVE_LEFT);
				_data->bodySprites->setState(_STATE_CONTRA_MOVE_LEFT);
			}
		}
		else {
			nextState = _DATA_CONTRA_STATE_IN_WATER;
			_data->state = _DATA_CONTRA_STATE_LAND_WATER;
			if (direction == 1) {
				_data->bodySprites->setState(_STATE_CONTRA_SWIM_RIGHT);
			} else {
				_data->bodySprites->setState(_STATE_CONTRA_SWIM_LEFT);
			}
		}
	}
}

void ContraStateLandWater::update()
{
	if (delayOnChange > 0) {
		delayOnChange--;
		_data->rect->X += direction * 2;
		_data->bodySprites->updateCurrent();
		_data->sprites->updateCurrent();
	} else {
		_data->notMove = false;
		_data->state = nextState;
	}
}

void ContraStateLandWater::draw(long time)
{
	if (_data->state == _DATA_CONTRA_STATE_WATER_LAND)
		_data->sprites->draw();
	_data->bodySprites->draw();
}

ContraStateLandWater::ContraStateLandWater(ContraData* data)
{
	_data = data;
}

bool ContraStateLandWater::checkIsShooting()
{
	return false;
}
